<template>
  <div class="container">
    <div class="app-container" style="padding: 20px;">
      <el-button size="mini" type="primary" style="margin: 10px 0;">添加权限</el-button>

      <el-table
        :data="tableData"
        style="width: 100%"
        row-key="id"
        border
        default-expand-all
        :header-cell-style="{background: '#f5f6f8'}"
      >
        <el-table-column prop="name" label="名称" width="400" />
        <el-table-column prop="code" label="标识" width="400" />
        <el-table-column prop="description" label="描述" width="400" />
        <el-table-column label="操作">
          <template #default="{row}">
            <el-button v-if="row.type === 1" type="text">添加</el-button>
            <el-button type="text">编辑</el-button>
            <el-button type="text">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import { getPermissionAPI } from '@/api/permission'
import convertToTree from '@/utils/data-conversion'
export default {
  name: 'Permission',
  data() {
    return {
      tableData: []
    }
  },
  created() {
    this.onLoad()
  },
  methods: {
    async onLoad() {
      const { data } = await getPermissionAPI()
      this.tableData = convertToTree(data)
    }
  }
}
</script>
